import { ProFormProps } from "../index.vue";
import { FromOptionsProp } from "../interface";

export const useSkip = (props: ProFormProps, model) => {
  // 页面跳转
  const skipPage = (item: FromOptionsProp) => {
    if (item?.attrs?.disabled) return;

    const { skipParams, prop } = item || {};
    const { customSkipMethod, url, params, disableDefaultSkip } = skipParams || {};
    if (!skipParams) {
      throw new Error("需配置skipParams字段,字段类型Object");
    }

    if (typeof customSkipMethod === "function") {
      // 记录当前跳转的标识
      customSkipMethod(model.value, prop);
      // 阻止默认跳转
      if (disableDefaultSkip) return;
    }

    // 页面跳转
    uni.navigateTo({
      url: transitionParams(params, url)
    });
  };

  return {
    skipPage
  };
};
